/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.pacs.tools;

import com.cxhd.pacs.DataConfig;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class MainTool {

    private static MainTool mainTool;
    private int count = 0;
    private String startCode = "30";

    public static MainTool getInstance() {

        if (mainTool == null) {
            mainTool = new MainTool();
        }
        return mainTool;
    }

    public synchronized int getCount() {
        System.out.println(DataConfig.getInstance().getIDDate());
        if (count == 0 && DataConfig.getInstance().getIDDate() != null) {
            String date = DataConfig.getInstance().getIDDate().split("@")[0];
            System.out.println(date.equalsIgnoreCase(DateUtil.getNum()));
            if (date.equalsIgnoreCase(DateUtil.getNum())) {
                count = Integer.parseInt(DataConfig.getInstance().getIDDate().split("@")[1]);
            }
        }
        System.out.println(count+"-----------------");
        count++;
        return count;
    }

    public String getHostId() {
        int count = getCount();
        String host = (Long.parseLong(startCode + DateUtil.getNum() + "0001") +count) + "";
        DataConfig.getInstance().setIDDate(count+"");
        return host;
    }

}
